---
title: Process your build
---

<ul class="main-content--version">
  <li>Current version:</li>
  <li><a href="/tutorials/getting-started/mac/process-build">Mac</a></li>
  <li><a class="active" href="/tutorials/getting-started/linux/process-build">Linux</a></li>
  <li><a href="/tutorials/getting-started/windows/process-build">Windows</a></li>
</ul>
<hr />

# Run your service
<%= partial "/shared/process_build_common" %>

## Run natively
Before we can run our service, we need to rebuild our package to include the changes made in the previous two steps.

1. If you are not in the studio environment, change over to your plan directory and enter the studio.

        cd ~/habitat-example-plans/mytutorialapp
        sudo hab studio enter

2. Build your mytutorialapp package.

        [1][default:/src:0]# build

   > Note: When you created an origin key pair in `hab setup`, you were also asked if you wanted to setup a default origin. If you said yes, then the `HAB_ORIGIN` environment variable is overridden for you with the default origin name you created. This action will also import the secret origin key that matches the overridden origin name when you call `hab studio enter`.

3. Because the studio is running natively in Linux, you can run your package from within the studio for quick testing purposes.

        [2][default:/src:0]# hab start /src/results/myorigin-mytutorialapp-0.2.0-20160829231756-x86_64-linux.hart

    You should see the supervisor start your Node.js application.

       hab-sup(MN): Starting myorigin/mytutorialapp/0.2.0/20160829231756
       hab-sup(TP): Child process will run as user=hab, group=hab
       hab-sup(GS): Supervisor 172.16.235.169: cee61553-b7a6-4e1b-b771-838dcb8a6376
       hab-sup(GS): Census mytutorialapp.default: 4e457dde-5f63-4a10-8a44-02e782748667
       hab-sup(GS): Starting inbound gossip listener
       hab-sup(GS): Starting outbound gossip distributor
       hab-sup(GS): Starting gossip failure detector
       hab-sup(CN): Starting census health adjuster
       hab-sup(SC): Updated config.json
       hab-sup(TP): Restarting because the service config was updated via the census
       mytutorialapp(SV): Starting
       mytutorialapp(O):
       mytutorialapp(O): > mytutorialapp@0.2.0 start /hab/svc/mytutorialapp/var
       mytutorialapp(O): > node server.js
       mytutorialapp(O):
       mytutorialapp(O): Running on http://0.0.0.0:8080


4. Connect to the Node.js app through your <a href="http://localhost:8080" target="_blank">localhost</a>.

    Here's an example of what you should see in your browser:

    ![Screen shot of node.js tutorial output](/images/nodejs-tutorial-output-linux.png)

5. You can also update the message value when your Habitat service starts up. To do this, you must pass in an
environment variable with the following format: `HAB_PACKAGENAME='keyname1=newvalue1 keyname2=newvalue2'`. For
multiline environment variables, such as those in a TOML table, it's preferrable to place your changes in a .toml
file and pass it in using `HAB_PACKAGENAME="$(cat foo.toml)"`.

    > Note: The package name in the environment variable must be uppercase, any dashes must be replaced with underscores, and if you are overriding values in a TOML table, you must override all values in the table.

    Here is how you change the message for mytutorialapp:

       [3][default:/src:0]# HAB_MYTUTORIALAPP='message = "Habitat rocks!"' hab start /src/results/blarg-mytutorialapp-0.2.0-20160829231756-x86_64-linux.hart

    Now refresh, or connect again to the local URL through your web browser.

    ![Screen shot of node.js output with new message](/images/nodejs-tutorial-update-output-linux.png)

### Run services outside of the studio
As mentioned above, running services from within the studio is great for testing purposes, but in a real deployment scenario, packages will be downloaded, installed, and then run outside of a studio environment.

To natively run services on your Linux host machine, do the following:

1. Build your package in the studio and then exit back to your host machine.
2. Add the `hab` user and group to your machine. This is the default user and group for the child process in a service and they must be present for your service to run.

      <%= partial "/shared/add_hab_user_group" %>

   > Note: One of the reasons you can run a service from within the studio is that the `hab` user is created for you when you enter the studio environment.

3. Run `sudo hab install path/to/results/packagefilename.hart`. This will install your package in the same location on the host machine as it does in the studio (i.e. `/hab/pkgs`). Make sure you are in the
`results` directory of `mytutorialapp` and the install the package.

       cd ~/habitat-example-plans/mytutorialapp/results
       sudo hab install myorigin-mytutorialapp-0.2.0-20160902224802-x86_64-linux.hart

4. Run `sudo hab start origin/packagename`.

       sudo hab start myorigin/mytutorialapp

   You can now connect to the Node.js app as you did earlier when running the service in the studio environment.

## (Optional) Run in a Docker container
To show the portability of Habitat, you can also export and run a Habitat service from within a Docker container through the following steps:

1. If your Linux distribution does not have the Docker engine installed, see [Install Docker Engine](https://docs.docker.com/engine/installation/) for the installation instructions.

2. Re-enter the studio.

       $ cd ~/habitat-example-plans/mytutorialapp
       $ sudo hab studio enter
       [1][default:/src:0]#

3. Create a Docker image containing your package by running `hab pkg export docker origin/packagename` with the origin and name of your package.

       [2][default:/src:0]# hab pkg export docker myorigin/mytutorialapp

    Habitat will proceed to unpack and install all necessary Habitat packages, including a Habitat supervisor, the mytutorialapp package, and all of its runtime dependencies. Then it will create an image using the Docker scratch image as the base and build up the rest of the image from there.

4. Once that process has completed, exit out of the studio and run a Docker container from any terminal window that has access to the Docker CLI on your host machine.

    > Note: We have to publish the Docker container port number to allow that container to be accessed by the host machine. Also, if you have not added your user to the `Docker` group, you will have to run `docker` with root privileges.

       $ docker run -it -p 8080:8080 myorigin/mytutorialapp

    You should see the supervisor start your Node.js application.

5. Because we are running this service in a Docker container on our host machine, connect to the Node.js app through the exposed container port on your <a href="http://localhost:8080" target="_blank">localhost</a>.

6. Just like when running a service natively, you can also re-run your Docker container and update the message value when your Habitat service starts up. To do this, pass in environment variables in the same manner as you did earlier.

       $ docker run -e HAB_MYTUTORIALAPP='message="Habitat rocks!"' -p 8080:8080 -it myorigin/mytutorialapp

Congratulations, you have successfully built a package from scratch, run it locally, and tested out some of the configuration capabilities!

<hr>
<ul class="main-content--button-nav">
  <li><a href="/tutorials/getting-started/next-steps" class="button cta">Next Steps</a></li>
  <li><a href="/tutorials/getting-started/linux/configure-plan/">Back to previous step</a></li>
</ul>
